package cn.wolfcode.cms.web.controller;

import cn.wolfcode.cms.annotation.PermissionName;
import cn.wolfcode.cms.domain.Stock;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IStockService;
import cn.wolfcode.cms.util.JSONResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//库存盘点单
@Controller
@RequestMapping("stock")
public class StockController {

    @Autowired
    private IStockService stockService;



    //库存盘点单信息列表/带分页
    @RequiresPermissions("stock:list")
    @PermissionName("库存盘点单首页")
    @RequestMapping("")
    public String index(){
        return "stock/list";
    }

    //库存盘点单信息列表/带分页
    @RequiresPermissions("stock:list")
    @PermissionName("库存盘点单首页")
    @RequestMapping("list")
    @ResponseBody
    public Object list(QueryObject qo){
        return stockService.query(qo);
    }

    //库存盘点单编辑
    @RequiresPermissions("stock:updateDate")
    @PermissionName("库存盘点单编辑")
    @RequestMapping("updateData")
    @ResponseBody
    public Object updateData(Stock entity,Integer newStockNumber){
        JSONResult result = new JSONResult();
        try {
            stockService.updateData(entity,newStockNumber);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("编辑失败");
        }
        return result ;
    }

    //库存盘点单删除
        @RequiresPermissions("stock:delete")
        @PermissionName("库存盘点单删除")
        @RequestMapping("delete")
        @ResponseBody
        public Object delete(Long id){
            JSONResult result = new JSONResult();
            try {
                stockService.delete(id);
            }catch (Exception e){
                e.printStackTrace();
                result.mark("删除失败");
            }
            return result ;
    }

}
